# coding=utf-8


from urllib.parse import urlencode

# 数据转url
data={'id':1234,'num':'中文','uid':'sd323'}
data=urlencode(data)
print(data)


# -----------------------------------------------------------
from urllib.request import quote, unquote
# 编码
url1 = "https://www.baidu.com/s?wd=中国"

# utf8编码，指定安全字符
ret1 = quote(url1, safe=";/?:@&=+$,", encoding="utf-8")
print(ret1)
# https://www.baidu.com/s?wd=%E4%B8%AD%E5%9B%BD

# gbk编码
ret2 = quote(url1, encoding="gbk")
print(ret2)
# https%3A//www.baidu.com/s%3Fwd%3D%D6%D0%B9%FA

# 解码
url3 = "https://www.baidu.com/s?wd=%E4%B8%AD%E5%9B%BD"

ret3 = unquote(url3, encoding='utf-8')
print(ret3)
# https://www.baidu.com/s?wd=中国